import TextRank.Operate;
import TextRank.OperateApi;
import TextRank.OperateStructure;
import TextRank.OperateStructureApi;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

public class Main {
    public static void main(String[] args) throws IOException {
        //只有源码
        Operate op = new Operate();
        //加上代码结构（只改变了摘要关键句的数量）
        OperateStructure ops = new OperateStructure();
        //加上api调用模式
        OperateApi opa = new OperateApi();
        //加上api代码结构和api调用模式
        OperateStructureApi opsa = new OperateStructureApi();
        //文件夹路径
        String netty = "resource/netty";
        String spring = "resource/spring-data-neo4j";
        String weld = "resource/weld";
        //arff文件路径
        String arffnetty = "resource/netty.arff";
        String arffspring = "resource/spring-data-neo4j.arff";
        String arffweld = "resource/weld.arff";

        List<String> list = getFilePath(netty);
        List<String> list2 = getFilePath(spring);
        List<String> list3 = getFilePath(weld);
        //处理netty
        for (String str:list) {
            op.Operate(str);
            ops.OperateStructure(str);
            opa.OperateApi(str,arffnetty);
            opsa.OperateStructureApi(str,arffnetty);
        }
        //处理spring
        for (String str:list2) {
            op.Operate(str);
            ops.OperateStructure(str);
            opa.OperateApi(str,arffspring);
            opsa.OperateStructureApi(str,arffspring);
        }
        //处理weld
        for (String str:list3) {
            op.Operate(str);
            ops.OperateStructure(str);
            opa.OperateApi(str,arffweld);
            opsa.OperateStructureApi(str,arffweld);
        }

        //todo 对于每个java文件将其中方法里面的内容获得

        //todo 设置一个判断函数，确定函数中需返回的关键句子个数

        //todo 将摘要一个java文件改成摘多个java文件，并写入文件中

        //todo 将api调用模式引入，将代码行替换成包.类.方法的形式
    }
    /**
     * 获取文件夹下所有文件的路径,只能获取当前文件夹下的
     *
     * @param folderPath
     * @return
     */
    public static List<String> getFilePath(String folderPath) {
        File folder = new File(folderPath);
        List<String> filePathList = new ArrayList<>();
        String rootPath;
        if (folder.exists()) {
            String[] fileNameList = folder.list();
            if (null != fileNameList && fileNameList.length > 0) {
                if (folder.getPath().endsWith(File.separator)) {
                    rootPath = folder.getPath();
                } else {
                    rootPath = folder.getPath() + File.separator;
                }
                for (String fileName : fileNameList) {
                    filePathList.add(rootPath + fileName);
                }
            }
        }
        return filePathList;
    }

}
